package com.czh.mock.result.config;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 配置生成mock结果的相关参数
 */
public class ResultConfig {
    /**
     * 生成的记录数目
     */
    private Integer count;
    /**
     * 分批写入时，每批写入的记录数目
     */
    private int batchCount = 500;
    private boolean overwrite = false;
    /**
     * 设置的文件名称
     */
    private String filename = "";
    /**
     * 写入的文件的绝对路径名称
     */
    private String absoluteFilename = "";

    protected ResultConfig() {
    }

    public static ResultConfig build() {
        return new ResultConfig();
    }

    public Integer getCount() {
        return count;
    }

    public ResultConfig setCount(Integer count) {
        this.count = count;
        return  this;
    }

    public boolean isOverwrite() {
        return overwrite;
    }

    public ResultConfig setOverwrite(boolean overwrite) {
        this.overwrite = overwrite;
        return this;
    }

    public String getFilename() {
        if (StringUtils.isBlank(this.filename)) {
            // 随机生成一个文件名
            this.filename = RandomStringUtils.randomAlphanumeric(10);
        }
        return this.filename;
    }

    public ResultConfig setFilename(String filename) {
        this.filename = filename;
        return this;
    }

    public String getAbsoluteFilename() {
        return absoluteFilename;
    }

    public ResultConfig setAbsoluteFilename(String absoluteFilename) {
        this.absoluteFilename = absoluteFilename;
        return this;
    }

    public int getBatchCount() {
        return batchCount;
    }

    public ResultConfig setBatchCount(int batchCount) {
        this.batchCount = batchCount;
        return this;
    }
}
